package com.pagepub.core.tag.validator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateDigital extends FormValidateBasic {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3755155309750981007L;

	/**
	 * @param args
	 */
	private String submitvalidate;

	private String rightimage;

	private String rightwordcolor;

	public static void main(String[] args) {
		// TODO 自动生成方法存根

	}

	@Override
	public int doStartTag() throws JspException {
		// TODO 自动生成方法存根
		JspWriter out = this.pageContext.getOut();

		try {
			out.print(this.checkNum());
			// System.out.println(this.checkNum());
		} catch (Exception e) {
			e.printStackTrace();
		}

		return 1;
	}

	public StringBuffer checkNum() {
		StringBuffer str = new StringBuffer();
		String emptyelement = "";
		String pluselement = "";
		if (this.submitvalidate.equalsIgnoreCase("true")) {
			emptyelement = "emptyelement(realname);";
			pluselement = "else pluselement(realname);";
		}
		str.append("<script language=\"javascript\">");
		str
				.append("function checknumber(realvalue,min,max,spanname,realname) {");
		// str.append("alert(realname);");
		str.append("if(realvalue!=\"\")");
		str.append("if(checknumberformat(realvalue,spanname,realname))");
		str
				.append("validatelengthdisplayrightmessage(realvalue,min,max,spanname,realname);");
		str.append(pluselement);
		str.append("else {");
		this.displayempty();
		str.append(emptyelement);
		str.append("}");
		str.append("}");
		str.append("</script>");
		str.append(this.checkNumformat());
		str.append(this.returnfunction());
		return str;
	}

	public StringBuffer checkNumformat() {
		StringBuffer str = new StringBuffer();
		str.append("<script language=\"javascript\">");
		str.append("function checknumberformat(str,spanname,realname){");
		// str.append("alert(realname);");
		str.append("if(str!=\"\") {");
		str.append("if(checkeNum(str)) {");
		str.append("	message=\"对不起,\"+realname+\"只能填写数字！\";		");
		str.append("	imgurl=\"<img src=\\\"" + this.wrongimage + "\\\"/>\";");
		str.append(this.display());
		str.append("return false;");

		str.append("} else ");
		str.append(this.displayempty());
		str.append("return true;");
		str.append("}  ");
		str.append("}");
		str.append("</script>");
		str.append(this.checknum());
		return str;
	}

	public StringBuffer returnfunction() {
		StringBuffer string = new StringBuffer();
		ValidateLengthDisplayRightMessage message = new ValidateLengthDisplayRightMessage();
		message.setRightimage(rightimage);
		message.setRightwordcolor(rightwordcolor);
		message.setSubmitvalidate(submitvalidate);
		message.setWordcolor(wordcolor);
		message.setWrongimage(wrongimage);
		string.append(message.validatelengthdisplayrightmessage());
		return string;
	}

	public String getRightimage() {
		return rightimage;
	}

	public void setRightimage(String rightimage) {
		this.rightimage = rightimage;
	}

	public String getRightwordcolor() {
		return rightwordcolor;
	}

	public void setRightwordcolor(String rightwordcolor) {
		this.rightwordcolor = rightwordcolor;
	}

	public String getSubmitvalidate() {
		return submitvalidate;
	}

	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}
}
